.class public abstract Lcom/felhr/usbserial/UsbSerialDevice;
.super Ljava/lang/Object;
.source "UsbSerialDevice.java"

# interfaces
.implements Lcom/felhr/usbserial/UsbSerialInterface;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;,
        Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;,
        Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;
    }
.end annotation


# static fields
.field private static mr1Version:Z


# instance fields
.field protected asyncMode:Z

.field protected final connection:Landroid/hardware/usb/UsbDeviceConnection;

.field protected final device:Landroid/hardware/usb/UsbDevice;

.field protected readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

.field protected serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

.field protected workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

.field protected writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .line 42
    sget v0, Landroid/os/Build$VERSION;->SDK_INT:I

    const/16 v1, 0x11

    if-le v0, v1, :cond_0

    const/4 v0, 0x1

    .line 43
    sput-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    goto :goto_0

    :cond_0
    const/4 v0, 0x0

    .line 45
    sput-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    :goto_0
    return-void
.end method

.method public constructor <init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;)V
    .locals 0

    .line 49
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 50
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->device:Landroid/hardware/usb/UsbDevice;

    .line 51
    iput-object p2, p0, Lcom/felhr/usbserial/UsbSerialDevice;->connection:Landroid/hardware/usb/UsbDeviceConnection;

    const/4 p1, 0x1

    .line 52
    iput-boolean p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->asyncMode:Z

    .line 53
    new-instance p1, Lcom/felhr/usbserial/SerialBuffer;

    sget-boolean p2, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    invoke-direct {p1, p2}, Lcom/felhr/usbserial/SerialBuffer;-><init>(Z)V

    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    return-void
.end method

.method static synthetic access$000(Lcom/felhr/usbserial/UsbSerialDevice;)Z
    .locals 0

    .line 17
    invoke-direct {p0}, Lcom/felhr/usbserial/UsbSerialDevice;->isFTDIDevice()Z

    move-result p0

    return p0
.end method

.method public static createUsbSerialDevice(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;)Lcom/felhr/usbserial/UsbSerialDevice;
    .locals 1

    const/4 v0, -0x1

    .line 58
    invoke-static {p0, p1, v0}, Lcom/felhr/usbserial/UsbSerialDevice;->createUsbSerialDevice(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)Lcom/felhr/usbserial/UsbSerialDevice;

    move-result-object p0

    return-object p0
.end method

.method public static createUsbSerialDevice(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)Lcom/felhr/usbserial/UsbSerialDevice;
    .locals 3

    .line 68
    invoke-virtual {p0}, Landroid/hardware/usb/UsbDevice;->getVendorId()I

    move-result v0

    .line 69
    invoke-virtual {p0}, Landroid/hardware/usb/UsbDevice;->getProductId()I

    move-result v1

    .line 71
    invoke-static {v0, v1}, Lcom/felhr/deviceids/FTDISioIds;->isDeviceSupported(II)Z

    move-result v2

    if-eqz v2, :cond_0

    .line 72
    new-instance v0, Lcom/felhr/usbserial/FTDISerialDevice;

    invoke-direct {v0, p0, p1, p2}, Lcom/felhr/usbserial/FTDISerialDevice;-><init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)V

    return-object v0

    .line 73
    :cond_0
    invoke-static {v0, v1}, Lcom/felhr/deviceids/CP210xIds;->isDeviceSupported(II)Z

    move-result v2

    if-eqz v2, :cond_1

    .line 74
    new-instance v0, Lcom/felhr/usbserial/CP2102SerialDevice;

    invoke-direct {v0, p0, p1, p2}, Lcom/felhr/usbserial/CP2102SerialDevice;-><init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)V

    return-object v0

    .line 75
    :cond_1
    invoke-static {v0, v1}, Lcom/felhr/deviceids/PL2303Ids;->isDeviceSupported(II)Z

    move-result v2

    if-eqz v2, :cond_2

    .line 76
    new-instance v0, Lcom/felhr/usbserial/PL2303SerialDevice;

    invoke-direct {v0, p0, p1, p2}, Lcom/felhr/usbserial/PL2303SerialDevice;-><init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)V

    return-object v0

    .line 77
    :cond_2
    invoke-static {v0, v1}, Lcom/felhr/deviceids/CH34xIds;->isDeviceSupported(II)Z

    move-result v0

    if-eqz v0, :cond_3

    .line 78
    new-instance v0, Lcom/felhr/usbserial/CH34xSerialDevice;

    invoke-direct {v0, p0, p1, p2}, Lcom/felhr/usbserial/CH34xSerialDevice;-><init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)V

    return-object v0

    .line 79
    :cond_3
    invoke-static {p0}, Lcom/felhr/usbserial/UsbSerialDevice;->isCdcDevice(Landroid/hardware/usb/UsbDevice;)Z

    move-result v0

    if-eqz v0, :cond_4

    .line 80
    new-instance v0, Lcom/felhr/usbserial/CDCSerialDevice;

    invoke-direct {v0, p0, p1, p2}, Lcom/felhr/usbserial/CDCSerialDevice;-><init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;I)V

    return-object v0

    :cond_4
    const/4 p0, 0x0

    return-object p0
.end method

.method public static isCdcDevice(Landroid/hardware/usb/UsbDevice;)Z
    .locals 6

    .line 201
    invoke-virtual {p0}, Landroid/hardware/usb/UsbDevice;->getInterfaceCount()I

    move-result v0

    const/4 v1, 0x0

    const/4 v2, 0x0

    :goto_0
    const/4 v3, 0x1

    add-int/lit8 v4, v0, -0x1

    if-gt v2, v4, :cond_1

    .line 204
    invoke-virtual {p0, v2}, Landroid/hardware/usb/UsbDevice;->getInterface(I)Landroid/hardware/usb/UsbInterface;

    move-result-object v4

    .line 205
    invoke-virtual {v4}, Landroid/hardware/usb/UsbInterface;->getInterfaceClass()I

    move-result v4

    const/16 v5, 0xa

    if-ne v4, v5, :cond_0

    return v3

    :cond_0
    add-int/lit8 v2, v2, 0x1

    goto :goto_0

    :cond_1
    return v1
.end method

.method private isFTDIDevice()Z
    .locals 1

    .line 196
    instance-of v0, p0, Lcom/felhr/usbserial/FTDISerialDevice;

    return v0
.end method


# virtual methods
.method public abstract close()V
.end method

.method protected killWorkingThread()V
    .locals 2

    .line 420
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    const/4 v1, 0x0

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    if-eqz v0, :cond_0

    .line 422
    invoke-virtual {v0}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->stopWorkingThread()V

    .line 423
    iput-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    goto :goto_0

    .line 424
    :cond_0
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    if-nez v0, :cond_1

    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    if-eqz v0, :cond_1

    .line 426
    invoke-virtual {v0}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->stopReadThread()V

    .line 427
    iput-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    :cond_1
    :goto_0
    return-void
.end method

.method protected killWriteThread()V
    .locals 1

    .line 451
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    if-eqz v0, :cond_0

    .line 453
    invoke-virtual {v0}, Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;->stopWriteThread()V

    const/4 v0, 0x0

    .line 454
    iput-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    .line 455
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v0}, Lcom/felhr/usbserial/SerialBuffer;->resetWriteBuffer()V

    :cond_0
    return-void
.end method

.method public abstract open()Z
.end method

.method public read(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)I
    .locals 2

    .line 118
    iget-boolean v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->asyncMode:Z

    if-nez v0, :cond_0

    const/4 p1, -0x1

    return p1

    .line 121
    :cond_0
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    if-eqz v0, :cond_1

    .line 123
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    if-eqz v0, :cond_2

    .line 124
    invoke-virtual {v0, p1}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->setCallback(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)V

    .line 125
    iget-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    invoke-virtual {p1}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->getUsbRequest()Landroid/hardware/usb/UsbRequest;

    move-result-object p1

    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v0}, Lcom/felhr/usbserial/SerialBuffer;->getReadBuffer()Ljava/nio/ByteBuffer;

    move-result-object v0

    const/16 v1, 0x4000

    invoke-virtual {p1, v0, v1}, Landroid/hardware/usb/UsbRequest;->queue(Ljava/nio/ByteBuffer;I)Z

    goto :goto_0

    .line 129
    :cond_1
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    invoke-virtual {v0, p1}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->setCallback(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)V

    :cond_2
    :goto_0
    const/4 p1, 0x0

    return p1
.end method

.method protected restartWorkingThread()V
    .locals 1

    .line 436
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    if-nez v0, :cond_0

    .line 438
    new-instance v0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    invoke-direct {v0, p0, p0}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;-><init>(Lcom/felhr/usbserial/UsbSerialDevice;Lcom/felhr/usbserial/UsbSerialDevice;)V

    iput-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    .line 439
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 440
    :goto_0
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->isAlive()Z

    move-result v0

    if-nez v0, :cond_1

    goto :goto_0

    .line 441
    :cond_0
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    if-nez v0, :cond_1

    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    if-nez v0, :cond_1

    .line 443
    new-instance v0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    invoke-direct {v0, p0, p0}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;-><init>(Lcom/felhr/usbserial/UsbSerialDevice;Lcom/felhr/usbserial/UsbSerialDevice;)V

    iput-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    .line 444
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 445
    :goto_1
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->isAlive()Z

    move-result v0

    if-nez v0, :cond_1

    goto :goto_1

    :cond_1
    return-void
.end method

.method protected restartWriteThread()V
    .locals 1

    .line 461
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    if-nez v0, :cond_0

    .line 463
    new-instance v0, Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    invoke-direct {v0, p0}, Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;-><init>(Lcom/felhr/usbserial/UsbSerialDevice;)V

    iput-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    .line 464
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 465
    :goto_0
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    invoke-virtual {v0}, Ljava/lang/Thread;->isAlive()Z

    move-result v0

    if-nez v0, :cond_0

    goto :goto_0

    :cond_0
    return-void
.end method

.method public abstract setBaudRate(I)V
.end method

.method public abstract setDataBits(I)V
.end method

.method public abstract setFlowControl(I)V
.end method

.method public abstract setParity(I)V
.end method

.method public abstract setStopBits(I)V
.end method

.method protected setThreadsParams(Landroid/hardware/usb/UsbRequest;Landroid/hardware/usb/UsbEndpoint;)V
    .locals 1

    .line 404
    sget-boolean v0, Lcom/felhr/usbserial/UsbSerialDevice;->mr1Version:Z

    if-eqz v0, :cond_0

    .line 406
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->workerThread:Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;

    invoke-virtual {v0, p1}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->setUsbRequest(Landroid/hardware/usb/UsbRequest;)V

    .line 407
    iget-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    invoke-virtual {p1, p2}, Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;->setUsbEndpoint(Landroid/hardware/usb/UsbEndpoint;)V

    goto :goto_0

    .line 410
    :cond_0
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice;->readThread:Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;

    invoke-virtual {p1}, Landroid/hardware/usb/UsbRequest;->getEndpoint()Landroid/hardware/usb/UsbEndpoint;

    move-result-object p1

    invoke-virtual {v0, p1}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->setUsbEndpoint(Landroid/hardware/usb/UsbEndpoint;)V

    .line 411
    iget-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice;->writeThread:Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;

    invoke-virtual {p1, p2}, Lcom/felhr/usbserial/UsbSerialDevice$WriteThread;->setUsbEndpoint(Landroid/hardware/usb/UsbEndpoint;)V

    :goto_0
    return-void
.end method
